import 'package:todo_flutter/todo_flutter.dart';

class QrCodeBlocObserver extends BlocObserver {
  @override
  void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
    super.onError(bloc, error, stackTrace);
    LogUtil.e('BeLifeBlocObserver：[${bloc.runtimeType}]-> $error');

    dismissLoading();
    if (bloc is! BaseBloc) {
      return;
    }

    if (bloc.isLoading()) {
      if (error is DomainException) {
        bloc.loadError(error);
      } else {
        bloc.loadError(UnknownException(error.toString()));
      }
    }
    if (error is ApiException) {
      showToast(error.entity.message ?? '信号不好，是不是断网了？');
    } else if (error is NetworkException) {
      showToast('信号不好，是不是断网了？');
    } else {
      showToast(error.toString());
    }
  }
}
